# encoding: utf-8

class TagController < ApplicationController
  def index
    @tags = Tag.active.all
  end
  
  def show
    @tag = Tag.find_by_name(params[:name])
    
    if @tag
		  @order = params[:order] = params[:order].blank? ? 'global_rating' : params[:order]
		  sort_mode = params[:sort_mode].blank? ? :desc : params[:sort_mode].to_sym
		  conditions = params[:cat1_id].blank? ? {} : { :cat1_id => params[:cat1_id] }
		  @items = Item.active.paginate :page => params[:page], :per_page => 16, :conditions => conditions, :order => @order
		  #@items = Item.active.search params[:name].gsub(/\/|\./, ''), :conditions => conditions, :page => params[:page], :per_page => 16, :order => @order, :sort_mode => sort_mode
    else
      flash[:notice] = '没有找到符合条件的标签'
      redirect_to root_path
    end
  end
end
